package io.geekidea.springbootplus.system.controller;

import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.system.entity.SysPermission;
import io.geekidea.springbootplus.system.entity.SysProduct;
import io.geekidea.springbootplus.system.entity.SysShare;
import io.geekidea.springbootplus.system.param.SysProductPageParam;
import io.geekidea.springbootplus.system.param.SysShare.SysSharePageParam;
import io.geekidea.springbootplus.system.service.SysShareService;
import io.geekidea.springbootplus.system.vo.SysBrowseQueryVo;
import io.geekidea.springbootplus.system.vo.SysProductQueryVo;
import io.geekidea.springbootplus.system.vo.SysShareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sysShare")
@Module("system")
@Api(value = "商品分享API", tags = {"商品分享"})
public class SysShareController extends BaseController {
    @Autowired
    private SysShareService sysShareService;

    @PostMapping("/add")
    @OperationLog(name = "插入分享数据", type = OperationLogType.ADD)
    @ApiOperation(value = "插入分享数据", response = ApiResult.class)
    public ApiResult<Boolean> addSysUser(@Validated(Add.class) @RequestBody SysShare SysShare) throws Exception {
        boolean flag = sysShareService.addSysShare(SysShare);
        return ApiResult.result(flag);
    }

    @GetMapping("/getSysBrowseList")
    @RequiresPermissions("sys:permission:all:menu:list")
    @OperationLog(name = "查看所有分享数据", type = OperationLogType.LIST)
    @ApiOperation(value = "查看所有分享数据", response = SysPermission.class)
    public ApiResult<List<SysShareQueryVo>> getSysBrowseList() throws Exception {
        List<SysShareQueryVo> list = sysShareService.getSysShare();
        return ApiResult.ok(list);
    }

    @PostMapping("/getPageListBy")
    @OperationLog(name = "分页查看分享数据", type = OperationLogType.PAGE)
    @ApiOperation(value = "分页查看分享数据", response = SysProductQueryVo.class)
    public ApiResult<Paging<SysShareQueryVo>> getSysSharePageList(@Validated @RequestBody SysSharePageParam sysSharePageParam) throws Exception {
        Paging<SysShareQueryVo> paging = sysShareService.getSysSharePageList(sysSharePageParam);
        return ApiResult.ok(paging);
    }


}
